package net.boar.os;

import java.io.*;
/**
 * @Author: zgl
 * @Date: 2021/6/23 11:03
 * @Description:
 */
public class OperatingSystemTest {
    private Floppy floppy = new Floppy();
    private void writeFileToFloppy(String fineName){
        File file = new File(fineName);
        InputStream in = null;
        try {
            in = new FileInputStream(file);
            byte[] buf = new byte[512];
            buf[510] = 0x55;
            buf[511] = (byte) 0xaa;
            while ((in.read(buf)) != -1){
                floppy.writeFloppy(Floppy.MAGNETIC_HEAD.MAGNETIC_HEAD_0,0,1,buf);
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public OperatingSystemTest(String s){
        writeFileToFloppy(s);
    }
    public void makeFloppy(){
        String s = "7788dassdfds";
        floppy.writeFloppy(Floppy.MAGNETIC_HEAD.MAGNETIC_HEAD_0,1,2,s.getBytes());
        floppy.makeFloppy(getPath() +"system.img");
    }

    public static void main(String[] args) {
        //nasm -o boot.bat boot.asm
        wrapper();
        OperatingSystemTest op = new OperatingSystemTest(getPath() + "boot.bat");
        op.makeFloppy();
    }
    private static void wrapper(){
        WorkerEntity entity = new WorkerEntity();
        entity.setCmd("nasm -o boot.bat boot.asm");
        entity.setWorkerPath(getPath());
        entity.setCreateBarName("build.bat");
        entity.setEncoding("GBK");
        Build.builder(entity);
    }
    private static String getPath(){
        return "D:\\project\\MgOS\\test\\";
    }
}
